using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class HandManager : MonoBehaviour
{
    // Start is called before the first frame update
    public static HandManager Instance { get; private set; }
    public Plant curPlant { get; private set; }
    private Vector3? curPlantPosition;
    private Cell curOverCell;


    private void Awake()
    {
        Instance = this;
    }
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        PlantMove();
    }
    public void ChangeCurPlant(Plant plant)
    {
        curPlant = plant;
    }

    public void FreeCurPlant()
    {
        GameObject.Destroy(curPlant.gameObject);
    }

    public void PlaceCurPlant(out Plant plant)
    {
        plant = curPlant;
        curPlant = null;
        
    }

    public void PlantFllowMouse()
    {
        if (curPlant != null)
        {
            Vector2 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            curPlant.transform.position = mouseWorldPosition;
        }
    }

    public void PlantMove()
    {
        if (curPlant&&curOverCell)
        {
            curPlant.transform.position = curOverCell.Position;

        }
        else
        {
            PlantFllowMouse();
        }
    }

    public void EnterCell(Cell cell)
    {
        curOverCell = cell;
    }

    public void ExitCell()
    {
        curOverCell = null;
    }





}




